// Package sysin
// @Link  https://github.com/bufanyun/hotgo
// @Copyright  Copyright (c) 2025 HotGo CLI
// @Author  Ms <133814250@qq.com>
// @License  https://github.com/bufanyun/hotgo/blob/master/LICENSE
// @AutoGenerate Version 2.15.11
package sysin

import (
	"context"
	"github.com/gogf/gf/v2/database/gdb"
	"hotgo/internal/model/entity"
	"hotgo/internal/model/input/form"

	"github.com/gogf/gf/v2/encoding/gjson"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gtime"
)

// StoreUpdateFields 修改门店管理字段过滤
type StoreUpdateFields struct {
	Name              string      `json:"name"              dc:"门店名称"`
	Address           string      `json:"address"           dc:"门店地址"`
	Lat               float64     `json:"lat"               dc:"纬度"`
	Lng               float64     `json:"lng"               dc:"经度"`
	Adcode            int64       `json:"adcode"            dc:"地区编码"`
	Phone             string      `json:"phone"             dc:"门店电话"`
	Location          int         `json:"location"          dc:"地理位置"`
	BusinessDay       *gjson.Json `json:"businessDay"       dc:"营业星期"`
	BusinessTimeStart int64       `json:"businessTimeStart" dc:"营业-开始时间"`
	BusinessTimeEnd   int64       `json:"businessTimeEnd"   dc:"营业-结束时间"`
	PublicityImgs     *gjson.Json `json:"publicityImgs"     dc:"门店图片"`
	BusinessId        int64       `json:"businessId"        dc:"关联的商户ID"`
}

// StoreInsertFields 新增门店管理字段过滤
type StoreInsertFields struct {
	Name              string      `json:"name"              dc:"门店名称"`
	Address           string      `json:"address"           dc:"门店地址"`
	Lat               float64     `json:"lat"               dc:"纬度"`
	Lng               float64     `json:"lng"               dc:"经度"`
	Adcode            int64       `json:"adcode"            dc:"地区编码"`
	Phone             string      `json:"phone"             dc:"门店电话"`
	Location          gdb.Raw     `json:"location"          dc:"地理位置"`
	BusinessDay       *gjson.Json `json:"businessDay"       dc:"营业星期"`
	BusinessTimeStart int64       `json:"businessTimeStart" dc:"营业-开始时间"`
	BusinessTimeEnd   int64       `json:"businessTimeEnd"   dc:"营业-结束时间"`
	PublicityImgs     *gjson.Json `json:"publicityImgs"     dc:"门店图片"`
	OldId             int64       `json:"oldId"             dc:"旧ID"`
	BusinessId        int64       `json:"businessId"        dc:"关联的商户ID"`
}

// StoreEditInp 修改/新增门店管理
type StoreEditInp struct {
	entity.Store
}

func (in *StoreEditInp) Filter(ctx context.Context) (err error) {
	// 验证门店名称
	if err := g.Validator().Rules("required").Data(in.Name).Messages("门店名称不能为空").Run(ctx); err != nil {
		return err.Current()
	}

	return
}

type StoreEditModel struct{}

// StoreDeleteInp 删除门店管理
type StoreDeleteInp struct {
	Id interface{} `json:"id" v:"required#ID不能为空" dc:"ID"`
}

func (in *StoreDeleteInp) Filter(ctx context.Context) (err error) {
	return
}

type StoreDeleteModel struct{}

// StoreViewInp 获取指定门店管理信息
type StoreViewInp struct {
	Id  int64   `json:"id" v:"required#ID不能为空" dc:"ID"`
	Lng float64 `json:"lng"     dc:"经度（114.038324）"`
	Lat float64 `json:"lat"     dc:"纬度（22.656084）"`
}

func (in *StoreViewInp) Filter(ctx context.Context) (err error) {
	return
}

type StoreViewModel struct {
	Distance float64 `json:"distance"       dc:"距离(km)"`
	entity.Store
}

// StoreListInp 获取门店管理列表
type StoreListInp struct {
	form.PageReq
	Name  string `json:"name" dc:"门店名称"`
	Phone string `json:"phone" dc:"门店电话"`
}

func (in *StoreListInp) Filter(ctx context.Context) (err error) {
	return
}

type StoreListModel struct {
	Id                   int64       `json:"id"                dc:"ID"`
	Name                 string      `json:"name"              dc:"门店名称"`
	Address              string      `json:"address"           dc:"门店地址"`
	Phone                string      `json:"phone"             dc:"门店电话"`
	CreatedAt            *gtime.Time `json:"createdAt"         dc:"创建时间"`
	Location             gdb.Raw     `json:"location"          dc:"地理位置"`
	Adcode               int64       `json:"adcode"            dc:"地区编码"`
	BusinessDay          *gjson.Json `json:"businessDay"       dc:"营业星期"`
	BusinessTimeStart    int64       `json:"businessTimeStart" orm:"business_time_start" dc:"营业-开始时间"`
	BusinessTimeEnd      int64       `json:"businessTimeEnd"   orm:"business_time_end" dc:"营业-结束时间"`
	PublicityImgs        *gjson.Json `json:"publicityImgs"     orm:"publicity_imgs" dc:"门店图片"`
	Balance              float64     `json:"balance"           description:"余额"`
	AdminMemberStoreName string      `json:"adminMemberStoreName"        dc:"关联的商户"`
}
